package com.vh.webapp.action;

import java.util.List;

import org.appfuse.service.GenericManager;
import org.springframework.beans.factory.annotation.Autowired;

import com.vh.model.Bday;

public class BdayAction extends BaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Autowired
	private GenericManager<Bday, Long> bdayManager;
	private List bdays;
	private Bday bday;
	private Long id;
	
	public String list() {
		bdays = bdayManager.getAll();
		log.debug("bdays Size:"+ bdays.size());
        return SUCCESS;
    }
	
	public String delete() {
		bdayManager.remove(new Long(bday.getId()));
	    saveMessage(getText("bday.deleted"));
	    return SUCCESS;
	}

	public String edit() {
	    if (id != null) {
	    	bday = bdayManager.get(id);
	    } else {
	    	bday = new Bday();
	    }

	    return SUCCESS;
	}


	public String save() throws Exception {
	    if (cancel != null) {
	        return CANCEL;
	    }

	    if (delete != null) {
	        return delete();
	    }

	    boolean isNew = (id == null);

	    bday = bdayManager.save(bday);

	    String key = (isNew) ? "bday.added" : "bday.updated";
	    saveMessage(getText(bday.getName()));

	    if (!isNew) {
	        return INPUT;
	    } else {
	        return SUCCESS;
	    }
	}
	
	public String saveBday(){
		bdayManager.save(bday);
		return SUCCESS;
	}

	public GenericManager<Bday, Long> getBdayManager() {
		return bdayManager;
	}

	public void setBdayManager(GenericManager<Bday, Long> bdayManager) {
		this.bdayManager = bdayManager;
	}

	public List getBdays() {
		return bdays;
	}

	public void setBdays(List bdays) {
		this.bdays = bdays;
	}

	public Bday getBday() {
		return bday;
	}

	public void setBday(Bday bday) {
		this.bday = bday;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	
	
	
	
}
